/**
 * OA
 */
XF.Site = new function(){
	
	this.edit = function(module,name){
		XF.lightSideBar(name);
		var data = {
			module:module,
			name:name
		};
		$.ajax({
			type:"post",
			url:global.contextPath + "/site/edit",
			data:data,
			complete:function(xhr){
				xhr = xhr['responseText'];
				$("#siteCenter").html(xhr);
			}
		});
	};
	
	this.refreshAfterModuleEdit = function(module,name){
		XF.Site.edit(module,name);
	};
	
	this.refreshAfterAddNews = function(){
		XF.Site.searchNews();
	};
	
	this.requestUrl = function(url,linkName){
		if(typeof(linkName)!='undefined'){
			XF.lightSideBar(linkName);
		}
		$.ajax({
			type:'post',
			url:global.contextPath + url,
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#siteCenter').html(xhr);
			}
		});
	};
	this.init = function(){
		$("#isimportant").change(function(){
			XF.Site.searchNews();
		});
		$("#istop").change(function(){
			XF.Site.searchNews();
		});
	};	
	this.init_css = function(){
	    $(".oaTable table.tableList tbody tr:not('#tableHeader')").hover(
            function () {
                $(this).addClass("hover");
            }, function () {
                $(this).removeClass("hover");
            }
        );
	};

	this.detail = function(id){
		var url  = global.contextPath + "/site/detail"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {id:id},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#siteCenter").html(xhr);
		  }
		});
	};

	this.feedbackDetail = function(id){
		var url  = global.contextPath + "/site/feedbackDetail"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {id:id},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#siteCenter").html(xhr);
		  }
		});
	};	
	
	/**
	 * 添加失败错误提示
	 */
	this.refreshAfterAddFaild = function(errorJson){
		$("[id^=errorTip]").hide();
		if(typeof(errorJson)=="undefined")return;
		if(errorJson==null || errorJson=="")return;
		for(key in errorJson){
			var v = errorJson[key];
			var errorTip = $("#errorTip_"+key);
			errorTip.html(v);
			errorTip.show();
		}
	};
	
	this.searchNews = function(){
		var group = $("#newsTab li[class=focus]").attr("group");
		_news_search('','',group);
	};

	this.searchFeedback = function(){
		_feedback_search('','','');
	};	
	
	this.searchNewsByGroup = function(group){
    	$("#istop").val("");
    	$("#isimportant").val("");
    	$("#keywords").val("");
    	_news_search('','',group);
    	XF.Site.searchNewsByGroupAfterHanlder(group);
    };
    
    this.searchNewsByGroupAfterHanlder = function(group){
    	var group0 = $("#newsTab li[group='0']");
    	var group1 = $("#newsTab li[group='1']");
    	group0.removeClass("focus");
    	group1.removeClass("focus");
    	if(group=="0"){
    		group0.addClass("focus");
    	}else if(group=="1"){
    		group1.addClass("focus");
    	}
    };
	

    this.editNews = function(id){
    	config.news_edit['args'] = [id];
    	SMT.ajax(config.news_edit);
    };
	this.deleteNews = function(id,group){
		
		$.messager.confirm('操作提示','确定删除这条新闻吗',function(data){
			if(data){
				$.ajax({
					url:""+global.contextPath+"/site/newsDelete",
					type:"post",
					data:"id="+id,
					success:function(data){
						$.messager.show({
							title:'提示',
							msg:'删除成功',
							timeout:3000,
							showType:'slide'
						});
						XF.Site.searchNewsByGroup(group);
					}
				});
			}
		});
		
	};

	this.editVideo = function(id){
		$.ajax({
			type:'post',
			url:global.contextPath + "/site/videoEdit",
			data:{id:id},
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#siteCenter').html(xhr);
			}
		});
	};

	this.editJob = function(id){
		$.ajax({
			type:'post',
			url:global.contextPath + "/site/jobEdit",
			data:{id:id},
			complete:function(xhr){
				xhr = xhr['responseText'];
				$('#siteCenter').html(xhr);
			}
		});
	};	
	
	this.videoDetail = function(id){
		var url  = global.contextPath + "/site/videoDetail"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {id:id},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#siteCenter").html(xhr);
		  }
		});
	};
	
	
	this.deleteVideo = function(id){
		$.messager.confirm('提示','确认删除这个视频吗?',function(r){
			if(r){
				var url = global.contextPath + "/site/deleteVideo";
				$.ajax({
					url:url,
					type:"post",
					data:{id:id},
					complete:function(xhr){
						xhr = xhr['responseText'];
						xhr = new Function('return' + xhr);
						xhr = xhr();
						xhr = xhr['status'];
						if(xhr=="SUCCESS"){
							$.messager.show({
								title:'提示',
								msg:'删除成功',
								timeout:3000,
								showType:'slide'
							});
							XF.Site.requestUrl('/site/videoList','videoList');
						}else if(xhr=="FAILD"){
							$.messager.show({
								title:'提示',
								msg:'删除失败',
								timeout:3000,
								showType:'slide'
							});
						}
					}
				});
			}
		});
	};

	this.deleteJob = function(id){
		$.messager.confirm('提示','确认删除这个职位吗?',function(r){
			if(r){
				var url = global.contextPath + "/site/deleteJob";
				$.ajax({
					url:url,
					type:"post",
					data:{id:id},
					complete:function(xhr){
						xhr = xhr['responseText'];
						xhr = new Function('return' + xhr);
						xhr = xhr();
						xhr = xhr['status'];
						if(xhr=="SUCCESS"){
							$.messager.show({
								title:'提示',
								msg:'删除成功',
								timeout:3000,
								showType:'slide'
							});
							XF.Site.requestUrl('/site/jobList','jobList');
						}else if(xhr=="FAILD"){
							$.messager.show({
								title:'提示',
								msg:'删除失败',
								timeout:3000,
								showType:'slide'
							});
						}
					}
				});
			}
		});
	};

	/**
	 * 删除简历
	 */
	this.deleteResume = function(id){
		$.messager.confirm('提示','确认删除这个简历吗?',function(r){
			if(r){
				var url = global.contextPath + "/site/deleteResume";
				$.ajax({
					url:url,
					type:"post",
					data:{id:id},
					complete:function(xhr){
						xhr = xhr['responseText'];
						xhr = new Function('return' + xhr);
						xhr = xhr();
						xhr = xhr['status'];
						if(xhr=="SUCCESS"){
							$.messager.show({
								title:'提示',
								msg:'删除成功',
								timeout:3000,
								showType:'slide'
							});
							XF.Site.listResume();
						}else if(xhr=="FAILD"){
							$.messager.show({
								title:'提示',
								msg:'删除失败',
								timeout:3000,
								showType:'slide'
							});
						}
					}
				});
			}
		});
	};	
	
	/**
	 * 管理职位
	 */
	this.listJob = function(){
		XF.lightSideBar("jobList");
		_job_search(null,null);
	};
	
	/**
	 * 管理简历
	 */
	this.listResume = function(){
		XF.lightSideBar("resumeList");
		_resume_search(null,null,null,null,null);
	};
	
	/**
	 * 管理视频
	 */
	this.listVideo = function(){
		XF.lightSideBar("videoList");
		_video_search(null,null);
	};
	
	/**
	 * seo编辑
	 */
	this.editSeo = function(id){
		$.ajax({
			type:"post",
			url:global.contextPath + "/site/seo/edit",
			data:{id:id},
			complete:function(xhr){
				xhr = xhr['responseText'];
				$("#siteCenter").html(xhr);
			}
		});
	};
	
	/**
	 * 简历搜索
	 */
    this.listResumeSearch = function(){
    	var orderByField = null;
    	var orderByMode = null;
		var jobName = $("#jobName").val();
		var createDateBegin =  $('#createDateBegin').datebox('getValue');
		var createDateEnd =  $('#createDateEnd').datebox('getValue');
		_resume_search(orderByField,orderByMode,jobName,createDateBegin,createDateEnd);
    	
    };	
	function _job_search(orderByField,orderByMode){
		
		config.job_search['args'] = [orderByField,orderByMode];
		SMT.xconfig.gvar.pageNum = '1';
		SMT.ajax(config.job_search);
	};
	
	function _resume_search(orderByField,orderByMode,jobName,createDateBegin,createDateEnd){
		config.resume_search['args'] = [orderByField,orderByMode,jobName,createDateBegin,createDateEnd];
		SMT.xconfig.gvar.pageNum = '1';
		SMT.ajax(config.resume_search);
	}
	
    function _news_search(orderByField,orderByMode,group){
		var istop = "";
	    var title = "";
	    var isimportant = "";
	    var isShow = "";
	    if($("#istop").length>0 && typeof($("#istop").val())!="undefined"){
	    	istop = $("#istop").val();
	    }
	    if($("#isimportant").length>0 && typeof($("#isimportant").val())!="undefined"){
	    	isimportant = $("#isimportant").val();
	    }
	    if($("#isShow").length>0 && typeof($("#isShow").val())!="undefined"){
	    	isShow = $("#isShow").val();
	    }
	    if($("#keywords").length>0 && typeof($("#keywords").val())!="undefined"){
	    	title = $("#keywords").val();
	    }
	    
    	config.news_search['args'] = [orderByField,orderByMode,title,isimportant,istop,isShow,group];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.news_search);
    };
    	
	function _video_search(orderByField,orderByMode){
		config.video_search['args'] = [orderByField,orderByMode];
		SMT.xconfig.gvar.pageNum = '1';
		SMT.ajax(config.video_search);
	};	

    function _feedback_search(orderByField,orderByMode,orderId){
	    var content = "";
	    var orderId = "";
	    var name = "";
	    if($("#keywords").length>0 && typeof($("#keywords").val())!="undefined"){
	    	content = $("#keywords").val();
	    }
	    if($("#orderId").length>0 && typeof($("#orderId").val())!="undefined"){
	    	orderId = $("#orderId").val();
	    }
	    if($("#name").length>0 && typeof($("#name").val())!="undefined"){
	    	name = $("#name").val();
	    }
	    config.feedback_search['args'] = [orderByField,orderByMode,content,orderId,name];
    	SMT.xconfig.gvar.pageNum = '1';
    	SMT.ajax(config.feedback_search);
    };
    

    /**
     * 管理周刊
     */
    this.listWeekly = function() {
    	XF.lightSideBar("weeklyList");
    	_weekly_search(null,null);
    };
    
	this.deleteWeekly = function(id){
		$.messager.confirm('提示','确认删除这个周刊吗?',function(r){
			if(r){
				var url = global.contextPath + "/site/doWeeklyDelete";
				$.ajax({
					url:url,
					type:"post",
					data:{weeklyId:id},
					complete:function(xhr){
						xhr = xhr['responseText'];
						xhr = new Function('return' + xhr);
						xhr = xhr();
						xhr = xhr['status'];
						if(xhr=="SUCCESS"){
							$.messager.show({
								title:'提示',
								msg:'删除成功',
								timeout:3000,
								showType:'slide'
							});
							XF.Site.listWeekly();
						}else if(xhr=="FAILD"){
							$.messager.show({
								title:'提示',
								msg:'删除失败',
								timeout:3000,
								showType:'slide'
							});
						}
					}
				});
			}
		});
	};
	
    function _weekly_search(orderByField,orderByMode) {
		config.weekly_search['args'] = [orderByField,orderByMode];
		SMT.xconfig.gvar.pageNum = '1';
		SMT.ajax(config.weekly_search);
    };
    
}();

config.weekly_search = {
		url:global.contextPath+"/site/weeklyList",
		argsOrder:['orderByField','orderByMode'],
		needVar:true,
		replaceExp:'#siteCenter',
		callBack:function(){
		}		
};

config.news_search = {
		url: ""+global.contextPath+"/site/newsList",
	    argsOrder: ['orderByField','orderByMode','title','isimportant','istop','isShow','group'],
	    needVar: true,
	    replaceExp: '#replaceDiv',	    
	    callBack: function() {
	    }		
};

config.feedback_search = {
		url: ""+global.contextPath+"/site/feedbackList",
	    argsOrder: ['orderByField','orderByMode','content','orderId','name'],
	    needVar: true,
	    replaceExp: '#siteCenter',	    
	    callBack: function() {
	    }		
};

config.job_search = {
		url:global.contextPath+"/site/jobList",
		argsOrder:['orderByField','orderByMode'],
		needVar:true,
		replaceExp:'#siteCenter',
		callBack:function(){
			
		}
};

config.resume_search = {
		url:global.contextPath+"/site/resumeList",
		argsOrder:['orderByField','orderByMode','jobName','createDateBegin','createDateEnd'],
		needVar:true,
		replaceExp:'#siteCenter',
		callBack:function(){
		}
};

config.video_search = {
		url:global.contextPath+"/site/videoList",
		argsOrder:['orderByField','orderByMode'],
		needVar:true,
		replaceExp:'#siteCenter',
		callBack:function(){
		}
};
config.news_edit = {
		url: ""+global.contextPath+"/site/newsEdit",
	    argsOrder: ['id'],
	    needVar: true,
	    replaceExp: '#siteCenter',
	    callBack: function() {
	    }			
};

config.news_delete = {
		url:""+global.contextPath+"/site/newsDelete",
		argsOrder:['id'],
		needVar:true,
	  
		callBack:function(){
			
		}
};